﻿using Core.SimpleTemp.Entitys;
using Core.SimpleTemp.Repositories.Internal;
using Core.Toolkit.Message;
using Core.Toolkit.Message.Model;
using System;
using System.Collections.Generic;
using System.Text;

namespace Core.SimpleTemp.Application.Message
{
    /// <summary>
    /// 数据库消息发送。
    /// </summary>
    public class DBMessage : IMessage
    {
        CoreDBContext _coreDBContext;
        public DBMessage(CoreDBContext coreDBContext)
        {
            _coreDBContext = coreDBContext;
        }

        public void SendMessage(MessageModel messageModel)
        {
            _coreDBContext.SysMessage.Add(new SysMessage()
            {
                BusiID = messageModel.BusiId,
                BusiType = messageModel.BusiType,
                Content = messageModel.Content,
                SendTime = messageModel.SendTime,
                FromUser = messageModel.FromUser,
                ToUser = messageModel.ToUser,
            });
            _coreDBContext.SaveChanges();
        }

        public void SendMessage(List<MessageModel> messageModel)
        {
            var inserList = new List<SysMessage>();
            foreach (var item in messageModel)
            {
                inserList.Add(new SysMessage()
                {
                    BusiID = item.BusiId,
                    BusiType = item.BusiType,
                    Content = item.Content,
                    SendTime = item.SendTime,
                    FromUser = item.FromUser,
                    ToUser = item.ToUser,
                });
            }
            _coreDBContext.SysMessage.AddRange(inserList);
            _coreDBContext.SaveChanges();
        }
    }
}
